package com.boil.qz.safekavass.pojo;

import com.boil.util.Constants;

import java.util.Set;
import java.util.TreeSet;

/**
 * Created by ChenYong on 2017-08-28.
 * <br>
 * 菜单映射实体类。
 */
public class MenuVo extends BaseVo implements Comparable<MenuVo> {
    /**
     * 父菜单编号
     */
    private Long parentId;
    /**
     * 菜单名称
     */
    private String name;
    /**
     * 菜单 URL
     */
    private String url;
    /**
     * 菜单图标
     */
    private String icon;
    /**
     * 菜单的层级
     */
    private Integer level;
    /**
     * 菜单的显示顺序：0-不按顺序显示；否则，值越小，越排在前
     */
    private Integer order;
    /**
     * 子菜单列表
     */
    private Set<MenuVo> childs;

    // 普通初始化块
    {
        childs = new TreeSet<MenuVo>();
    }

    /**
     * 默认构造器。
     */
    public MenuVo() {
        super();
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public Integer getOrder() {
        return order;
    }

    public void setOrder(Integer order) {
        this.order = order;
    }

    public Set<MenuVo> getChilds() {
        return childs;
    }

    public void setChilds(Set<MenuVo> childs) {
        this.childs = new TreeSet<MenuVo>(childs);
    }

    @Override
    public int compareTo(MenuVo o) {
        if ((this == null) || (o == null)) {
            return Constants.VALUE_0;
        }

        return this.getOrder().compareTo(o.getOrder());
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("MenuVo{");
        sb.append("parentId=").append(parentId);
        sb.append(", name='").append(name).append('\'');
        sb.append(", url='").append(url).append('\'');
        sb.append(", icon='").append(icon).append('\'');
        sb.append(", level=").append(level);
        sb.append(", order=").append(order);
        sb.append(", childs=").append(childs);
        sb.append(", id=").append(id);
        sb.append('}');
        return sb.toString();
    }
}